
<%-- 
    Document   : layout
    Created on : 24.11.2012, 10:12:33
    Author     : mprokes
--%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>

<f:message key="players.index.title" var="title" /> 
<s:layout-render name="/layout.jsp" title="${title}">        
    <s:layout-component name="content">        

        <s:useActionBean beanclass="cz.muni.fi.pa165.sportclubmanager.web.PlayersActionBean" var="actionBean"/>
        
        <h1><c:out value="${title}" /></h1>
        
        <div class="list-options">
            <sec:authorize access="hasRole('ROLE_ADMIN')">
                <s:link beanclass="${actionBean.getClass()}" event="edit" class="button">
                    <span class="icon icon-plus"></span> 
                    <f:message key="player.add.title" />
                </s:link>
            </sec:authorize>
        </div>

        <table class="table" width="100%" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th class="table-column-id">id</th>
                    <th><f:message key="player.firstName"/></th>
                    <th><f:message key="player.lastName"/></th>
                    <th><f:message key="player.birthDate"/></th>
                    <th><f:message key="player.weight"/></th>
                    <th><f:message key="player.height"/></th>  
                    <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <th class="table-column-options"><f:message key="web.actions"/></th>
                    </sec:authorize>
                </tr>
            </thead>
            <tbody>
              <c:choose>
                <c:when test="${actionBean.players == null || actionBean.players.isEmpty()}">
                    <tr class="table-row-empty">
                        <td colspan="7">
                            <f:message key="web.tableIsEmpty" />
                        </td>
                    </tr>
                </c:when>
                <c:otherwise>
                    <c:forEach items="${actionBean.players}" var="player">
                        <tr>
                            <td class="table-column-id">${player.id}</td>
                            <td>${player.firstName}</td>
                            <td>${player.lastName}</td>
                            <td>${player.birthDate}</td>
                            <td>${player.weight}</td>
                            <td>${player.height}</td>
                            <sec:authorize access="hasRole('ROLE_ADMIN')">
                                <td class="table-column-options">
                                    <s:link beanclass="${actionBean.getClass()}" event="edit" title="${action.edit}">
                                        <s:param name="player.id" value="${player.id}"/>
                                        <span class="icon icon-edit"></span>
                                    </s:link>
                                    <s:link beanclass="${actionBean.getClass()}" event="delete" title="${action.delete}" rel="delete-item">
                                        <s:param name="player.id" value="${player.id}"/>
                                        <span class="icon icon-delete"></span>
                                    </s:link>
                                </td>
                            </sec:authorize>
                        </tr>
                    </c:forEach>
                </c:otherwise>
              </c:choose>
            </tbody>
        </table>

        <f:message key="player.action.delete.confirm" var="deleteConfirmMessage"/>

        <script>
            $(function() {
                $('[rel="delete-item"]').click(function() {
                    return confirm('${deleteConfirmMessage}');
                });
            })
        </script>
    </s:layout-component>        
</s:layout-render>
